package com.nopay.cdxphone.dialog;

import android.app.Activity;
import android.app.Dialog;
import android.os.Bundle;
import androidx.annotation.NonNull;
import com.nopay.cdxphone.R;

public class DialogUserAgreementAndPrivacy extends Dialog {

    public DialogUserAgreementAndPrivacy(@NonNull Activity context) {
        super(context, R.style.MyDialog);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_user_agreement_and_privacy);
        setCancelable(false);

        findViewById(R.id.tv_user_agreement).setOnClickListener(v -> {
            if(onAgreementClickListener != null) onAgreementClickListener.openAgree(true);
        });

        findViewById(R.id.tv_privacy).setOnClickListener(v -> {
            if(onAgreementClickListener != null) onAgreementClickListener.openAgree(false);
        });

        findViewById(R.id.tv_dialog_cancel).setOnClickListener(v -> {
            dismiss();
            if(onAgreementClickListener != null) onAgreementClickListener.doAgree(false);
        });
        findViewById(R.id.tv_dialog_confirm).setOnClickListener(v -> {
            dismiss();
            if(onAgreementClickListener != null) onAgreementClickListener.doAgree(true);
        });
    }

    private OnAgreementClickListener onAgreementClickListener;

    public DialogUserAgreementAndPrivacy setOnAgreementClickListener(OnAgreementClickListener onAgreementClickListener) {
        this.onAgreementClickListener = onAgreementClickListener;
        return this;
    }

    public interface OnAgreementClickListener {

        void openAgree(boolean isUser);

        void doAgree(boolean agree);
    }
}
